package open.template.work.udm.client.feign;

import feign.hystrix.FallbackFactory;
import open.template.work.commons.constants.CloudServerDirectory;
import open.template.work.commons.vo.udm.request.TaskRequestVo;
import open.template.work.commons.vo.udm.resposne.TaskReponseVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(name = CloudServerDirectory.UDM_SERVER,fallbackFactory = FeignCLientFallbackFactory.class)
public interface UdmServerTaskFegin {

    @RequestMapping("/task/get")
    TaskReponseVo getTaskInfo(@RequestBody TaskRequestVo vo);
}

@Component
class FeignCLientFallbackFactory implements FallbackFactory<UdmServerTaskFegin>{

    private static final Logger  LOGGER=LoggerFactory.getLogger(FeignCLientFallbackFactory.class);

    @Override
    public UdmServerTaskFegin create(final Throwable throwable) {

        return new  UdmServerTaskFegin(){
            @Override
            public TaskReponseVo getTaskInfo(TaskRequestVo vo) {
                LOGGER.info("udm server fallback,reason was:{}",throwable==null?"空异常":throwable.getMessage());
                TaskReponseVo responseVo=new TaskReponseVo();
                responseVo.setStatus("0");
                responseVo.setTaskId("0");
                return responseVo;
            }
        };
    }
}